home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 319.adf / CNewsSrc / cnews.src.lzh / libcnews / hostname.c < prev    next >
C/C++ Source or Header  |  1989-07-14  |  979b  |  44 lines

  1. /*
  2.  * hostname - return the Usenet name of this machine
  3.  *
  4.  * One interesting possibility would be to assume that the first
  5.  * name in the sys file is our Usenet name, unless it is "ME",
  6.  * which would require our current strategy anyway.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <sys/types.h>
  11.  
  12. #include "libc.h"
  13. #include "news.h"
  14. #include "config.h"
  15.  
  16. /* 2BSD funniness */
  17. #ifdef BSD2_10
  18. # include <short_names.h>
  19. #endif
  20.  
  21. #ifndef NAMEFILE
  22. #define NAMEFILE ctlfile("whoami")
  23. #endif
  24.  
  25. char *hostname()            /* return this Usenet machine's name */
  26. {
  27.     static char name[MAXHOST];
  28.  
  29.     if (name[0] == '\0') {    /* try to get the "news hostname" */
  30.         register FILE *fp;
  31.  
  32.         fp = fopenclex(NAMEFILE, "r");
  33.         if (fp != NULL) {
  34.             (void) fgets(name, sizeof name, fp);
  35.             (void) nfclose(fp);
  36.             if (name[0] != '\0' && name[strlen(name) - 1] == '\n')
  37.                 name[strlen(name) - 1] = '\0';
  38.         }
  39.     }
  40.     if (name[0] == '\0')    /* else use the ordinary hostname */
  41.         (void) gethostname(name, sizeof name);
  42.     return name;
  43. }
  44.